package com.project.conroller;

import com.project.DTO.AdminDTO;
import com.project.DTO.AdminAndInsuranceDTO;
import com.project.feign.OrderClient;
import com.project.vo.AdminVO;
import com.project.pojo.Admin;
import com.project.service.AdminService;
import com.project.utils.ResponseData;
import com.project.utils.ResultEnums;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    AdminService adminService;
    @Autowired
    OrderClient orderClient;
    /**
     * 登录
     * @param adminDTO
     * @return
     */
    @RequestMapping("/login")
    public ResponseData<AdminVO> login(@RequestBody  AdminDTO adminDTO){
        Admin adminByName = adminService.getAdminByName(adminDTO.getUsername());
        if (adminByName==null){
            return new ResponseData(ResultEnums.NOT_FOUND);
        }else {
            if (adminDTO.getPassword().equals(adminByName.getPassword())){
                return new ResponseData<AdminVO>(ResultEnums.OK,new AdminVO(adminByName.getId(),adminByName.getUsername(),adminByName.getType()));
            }
        }
        return new ResponseData(ResultEnums.NOT_FOUND);
    }

    /**
     * 审核通过
     * @param adminAndInsuranceDTO
     * @return
     */
    @RequestMapping("/passcheck")
    public ResponseData InsurancePass(@RequestBody AdminAndInsuranceDTO adminAndInsuranceDTO){
        if (adminAndInsuranceDTO.getAdminType()==1){
            return orderClient.updateOrderWithSuccessByOne(adminAndInsuranceDTO);
        }else {
            return orderClient.updateOrderWithSuccessByTwo(adminAndInsuranceDTO);
        }

    }
    /**
     * 审核不通过
     * @param adminAndInsuranceDTO
     * @return
     */
    @RequestMapping("/notpasscheck")
    public ResponseData InsuranceNotPass(@RequestBody AdminAndInsuranceDTO adminAndInsuranceDTO){
        if (adminAndInsuranceDTO.getAdminType()==1){
            return orderClient.updateOrderWithFailure(adminAndInsuranceDTO);
        }else {
            return orderClient.updateOrderWithFailure(adminAndInsuranceDTO);
        }
    }
}
